<style rel="stylesheet/scss" lang="scss" scoped>
@import "../../../styles/prod.scss";
</style>
<template>
  <div class="app-container calendar-list-container">
    <div class="">
      <div class="pds-tip">
        <div class="title">产品策划</div>
      </div>
      <div class="">
        <el-button class="filter-item pds-success" type="success" icon="search" @click="$router.push({path:'plan/add'})">新增</el-button>
        <div class="filter-container" style="float:right">
          <el-input style="width: 200px;" class="filter-item" placeholder="请输入项目编号或产品型号" v-model="pageData.params.key">
          </el-input>
          <el-button class="filter-item" type="primary" icon="search" @click="search()">查询</el-button>
        </div>
      </div>
      <el-table :data="pageData.list" border fit highlight-current-row style="width: 100%">
        <!-- <el-table-column fixed type="index" align="center" label="序号" width="50" :index="indexMethod"></el-table-column> -->
        <el-table-column width="50" align="center" label="序号">
          <template slot-scope="scope">
            {{(pageData.params.page-1)*pageData.params.limit+(scope.$index+1)}}
          </template>
        </el-table-column>
        <el-table-column width="" align="center" label="项目编号" prop="productPlanningNo"></el-table-column>
        <el-table-column width="" align="center" label="产品品类" prop="pdsConfCategory.nameCn"></el-table-column>
        <el-table-column width="" align="center" label="产品型号" prop="productModel"></el-table-column>
        <el-table-column width="" align="center" label="产品名称" prop="productName"></el-table-column>
        <el-table-column width="" align="center" label="市场定位" prop="pdsPlanningInfo.marketPositionDv"></el-table-column>
        <el-table-column width="" align="center" label="业务模式" prop="productBizModelDv"></el-table-column>
        <el-table-column width="" align="center" label="发行日期">
          <template slot-scope="scope">
            {{scope.row.createTime.slice(0,10)}}
          </template>
        </el-table-column>
        <el-table-column width="" align="center" label="编辑状态">
          <template slot-scope="scope">
            <span v-if="scope.row.status===0">草稿</span>
            <span v-if="scope.row.status===1">审核中</span>
            <span v-if="scope.row.status===2">已发布</span>
            <span v-if="scope.row.status===3">已删除</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="操作" width="230px">
          <template slot-scope="scope">
            <el-button size="small" type="success" @click="$router.push({path:'/product/plan/detail',query:{planId:scope.row.id}})">查看</el-button>
            <el-button size="small" type="primary" @click="$router.push({path:'/product/plan/edit',query:{planId:scope.row.id}})" v-if="scope.row.status==0||scope.row.status==2">{{scope.row.status==2?'变更':'编辑'}}
            </el-button>
            <el-button size="small" type="danger" v-if="scope.row.status===0" @click="handleDelete(scope.row)">删除
            </el-button>
            <el-button size="small" type="warning" v-if="scope.row.status===2" @click="$router.push({path:'/product/plan/detail',query:{planId:scope.row.id,type:'export'}})">导出
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination :pageData="pageData.params" @pageChange="changePage" @changeSize="changeSize"></pagination>
    </div>

  </div>
</template>
<script>
import {
  mapGetters
} from 'vuex';
import * as api from '@/api/product/plan/index';
import ListRefresh from '@/components/Mixin/listRefresh.js'
export default {
  name: 'user',
  components: {
    // 'depart-selector': () =>
    //   import ('./components/departSelector')
  },
  mixins: [ListRefresh],
  data() {
    return {
      pageData: {
        params: {
          page: 1,
          limit: 10,
          total: 100
        },
        list: []
      }
    };
  },
  created() {
    this.getList();
  },
  computed: {
    ...mapGetters(['elements'])
  },
  methods: {
    refresh() {
      this.pageData.params.page = 1;
      this.getList();
    },
    handleDelete(row) {
      console.log(row)
      this.$confirm('此操作将永久删除该条数据, 是否继续?', '提示', {
        type: 'warning'
      }).then(() => {
        const params = {
          id: row.id
        };
        api.removePlan(params).then(response => {
          console.log(response)
          if (response.code === 200) {
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
            this.getList()
          }
        })
      })
    },
    indexMethod(index) {
      return index + 1
    },
    search() {
      this.pageData.params.page = 1
      this.getList()
    },
    changePage(pageData) {
      this.pageData.params.page = pageData.page;
      this.getList();
    },
    changeSize(pageSize) {
      this.pageData.params.limit = pageSize;
      this.pageData.params.page = 1;
      this.getList();
    },
    getList() {
      const params = Object.assign({}, this.pageData.params);
      delete params.total;
      api.getList(params).then(response => {
        console.log(response)
        if (response.code === 200) {
          this.pageData.list = response.data.rows;
          this.pageData.params.total = response.data.total;
        }
      });
    },
    /* 导出 */
    exportPdf(id) {
      // api.exportPdf({id}).then(res => {
      //   console.log(res);
      // })
      window.open(api.exportPdf(id))
    }
  }
};

</script>
